<template>
    <div class="box">
        <div class="box-hd">
            <div class="title-wrap">
                <div class="title">详细信息</div>
            </div>
        </div>
        <div class="box-bd">
            <div class="profile" v-if="group">
                <div class="avatar" style="display: flex;justify-content: center;">
                    <bgroup-avatar :id="group.id"></bgroup-avatar>
                    <!--<img class="img" :src="group.group_icon" alt="" v-if="group.group_icon != ''">-->
                    <!--<img class="img" src="../../assets/group_icon.png" alt="" v-else>-->
                </div>
                <div class="remark">{{group.group_name}}</div>
                <div class="action">
                    <el-button class="custom-btn" type="primary" @click="chooseGroup()">发送消息</el-button>
                </div>
            </div>
            <div class="none" v-else>
                <img class="img img2" src="../../assets/no_group.png" v-if="!groupList || groupList.length == 0">
                <img class="img" src="../../assets/no_message.png" v-else>
                <div class="text">{{ !groupList || groupList.length == 0 ? '暂无群聊' : '未选择群聊' }}</div>
            </div>
        </div>
    </div>
</template>
<script>
import { baseApi } from '@/api'
import bgroupAvatar from '@/components/group-avatar/bigIndex'
export default {
    components: {
        bgroupAvatar
    },
    computed: {
        group() {
            return this.$store.state.base.currentGroup
        },
        groupList() {
            return this.$store.state.base.friendList
        }
    },
    methods: {
        chooseGroup() {
            baseApi.getGroupSubs({ group_id: this.group.id }).then(res => {
                if (res.code == 200) {
                    this.$store.dispatch('setCrrentGroupSubs', res.data)
                    let params = {
                        id: this.group.id,
                        icon: this.group.group_icon,
                        name: this.group.group_name,
                        time: '',
                        count: 0,
                        status: this.group.status,
                        msgType: 13,
                        msgData: [],
                        mute: this.group.mute
                    }
                    let inputObj = {
                        content: '',
                        atUserList: [],
                        type: 'group',
                        id: this.group.id
                    }
                    this.$store.dispatch('insertChatInput', inputObj)
                    this.$store.dispatch('createChat', params)
                    this.$router.push({ path: '/message' })
                } else {
                    // this.$socket.close()
                    this.$confirm('您的授权已失效，请重新登录！', '提示', {
                        confirmButtonText: '知道了',
                        showClose: false,
                        showCancelButton: false,
                        closeOnClickModal: false,
                        closeOnPressEscape: false,
                        type: 'warning'
                    }).then(() => {
                        sessionStorage.removeItem('key')
                        this.$store.dispatch('resetBase')
                        this.$store.dispatch('resetChat')
                        this.$router.push({ path: '/login' })
                        // window.location.href = window.location.protocol + '//' + window.location.host + '/login'
                    })
                }
            })
        }
    }
}
</script>
